!pip install geopandas
import numpy as np
import pandas as pd
import geopandas as gpd
import folium
import datetime
from IPython.display import HTML, display
fp = '/content/query.csv'
eartt=pd.read_csv(fp)
eartt.head()
eartt1=eartt.rename({'time':'time_hour'}, axis=1)
eartt1.head()
type(eartt1.loc[0,'time_hour'])
eartt1['time_hour']=eartt1['time_hour'].str[:-5]
eartt1['time_hour']=pd.to_datetime(eartt1['time_hour'])
eartt1=eartt1.set_index('time_hour')
eartt1['type']= 'ss'
eartt1.head(1)
start = eartt1.pivot_table('id',
index = ['place', 'time_hour',
'latitude',
'longitude',
'mag'
],
columns = 'type',
aggfunc='count').reset_index()
start.head()
start['time_hour']=pd.to_datetime(start['time_hour'])
start['time_hh']=start['time_hour'].dt.hour
start.head()
3352FF Blue
FCFF33 Yellow
FF33EC Pink
FF334C Red
start.loc[start['mag']<7, 'fillcolor']='#3352FF ' # Earthquakes with magnitude less than 7 = blue color
start.loc[start['mag']>=7, 'fillcolor']='#FF33EC' # Earthquakes with magnitude bigger or equal than 7 = pink color
start.loc[start['mag']>=8, 'fillcolor']='#FCFF33' # Earthquakes with magnitude bigger or equal than 8 = yellow color
start.loc[start['mag']>=9, 'fillcolor']='#FF334C' # Earthquakes with magnitude bigger or equal than 9 = red color
start.shape
start.head()
start['mag']= (start['mag'] - start['mag'].min())/(start['mag'].max()-start['mag'].min())
#df["A"] = (df["A"]-df["A"].min()) / (df["A"].max()-df["A"].min())
start['mag'].head()
def create_geojson_features(df):
features = []
for _, row in df.iterrows():
feature = {
'type': 'Feature',
'geometry': {
'type':'Point',
'coordinates':[row['longitude'],row['latitude']]
},
'properties': {
'time': pd.to_datetime(row['time_hh'], unit='h').__str__(),
'style': {'color' : ''},
'icon': 'circle',
'iconstyle':{
'fillColor': row['fillcolor'],
'fillOpacity': 0.8,
'stroke': 'true',
'radius': row['mag']*10
}
}
}
features.append(feature)
return features
start_geojson = create_geojson_features(start)
start_geojson[0]
from folium.plugins import TimestampedGeoJson
EQ_map = folium.Map(location = [2, -2],
tiles = "CartoDB Positron",
zoom_start = 2)
TimestampedGeoJson(start_geojson,
period = 'PT1H',
duration = 'PT1H',
transition_time = 1000,
auto_play = True).add_to(EQ_map)
EQ_map
EQ_map.save('EQ_map.html', title='Earthquakes with Magnitude 6 and higher since 1968')